import { resolveDirective } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/dashboard',
    },
    {
      path:'/login',
      component:()=>import('@/views/Login.vue')
    },
    {
      path:'/dashboard',
      component: () => import('@/views/Dashboard.vue'),
      children:[
        {
          path:'welcome',
          component: () => import('@/views/dashboard/Welcome.vue')
        },
        {
          path: 'user',
          component: () => import('@/views/dashboard/user/User.vue'),
          children: [
            {
              path: 'index',
              component: () => import('@/views/dashboard/user/Index.vue'),
            }
          ]
        },
      ]
    },
    
    // {
    //   path: '/film',
    //   component: () => import('@/views/dashboard/film/Film.vue'),
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/dashboard/film/Index.vue'),
    //     }
    //   ]
    // },
    // {
    //   path: '/college',
    //   component: () => import('@/views/dashboard/college/College.vue'),
    //   children: [
    //     {
    //       path: 'index',
    //       component: () => import('@/views/dashboard/college/Index.vue'),
    //     }
    //   ]
    // },

  ]
})


export default router


router.beforeEach((to, from) => {

  let userInfo = JSON.parse(localStorage.getItem('acl'));

  if (to.path == '/login') {
    if (userInfo) {
      ElMessage({
        message: '您已经登录过啦,无需重复登录',
        type: 'warning',
        duration: 1000,
      })

      return { path: '/home' }
    }

  } else {

    if (!userInfo) {
      ElMessage({
        message: '请先登录',
        type: 'warning',
        duration: 1000
      })

      return { path: '/login' }
    }

  }
})

